<?php 

namespace app\controller\bossManager;

use app\exception\ErrnoPlus;
use app\service\AdminAcountService;
use app\validate\LoginValidate;

class LoginController extends WebBossController{
    
    protected $beforeActionList = [
    ];


    public function initValidate(){
        $this->validate = new LoginValidate();
    }

    /**
     * 设置临时密码
     */
    public function login_action(){
        $data = $this->getAESDecodeData();
        $param = $this->check('webLogin',$data);
        $accountInfo = AdminAcountService::getByAccount($param['account']);
        if(empty($accountInfo)){
            return self::fail("account or password error",ErrnoPlus::USER_NOT_EXISTS); 
        }
        if($accountInfo['password'] !== $param['password']){
            return self::fail("password or account error",ErrnoPlus::COMMON_ERROR); 
        }
        if(intval($accountInfo['level']) > 0){
            return self::fail("please login as super admin",ErrnoPlus::COMMON_ERROR); 
        }
        $token = self::authToken($accountInfo);
        return self::ok(['token' => $token]);
    }
  
   
}
